### Terminate gracefully

The following Dagger Function demonstrates how to handle errors in a workflow.


<Tabs groupId="language" queryString="sdk">
<TabItem value="go" label="Go">

```go file=../../../cookbook/snippets/handle-errors/go/main.go
```

</TabItem>
<TabItem value="python" label="Python">

```python file=../../../cookbook/snippets/handle-errors/python/main.py
```

</TabItem>
<TabItem value="typescript" label="TypeScript">

```typescript file=../../../cookbook/snippets/handle-errors/typescript/index.ts
```

</TabItem>
<TabItem value="php" label="PHP">

```php file=../../../cookbook/snippets/handle-errors/php/src/MyModule.php
```

</TabItem>
</Tabs>

#### Example

Execute a Dagger Function which creates a container and runs a command in it. If the command fails, the error is captured and the Dagger Function is gracefully terminated with a custom error message.

    <Tabs groupId="shell">
    <TabItem value="System shell">
    ```shell
    dagger -c test
    ```
    </TabItem>
    <TabItem value="Dagger Shell">
    ```shell title="First type 'dagger' for interactive mode."
    test
    ```
    </TabItem>
    <TabItem value="Dagger CLI">
    ```shell
    dagger call test
    ```
    </TabItem>
    </Tabs>
